package com.gxa.servlet.goods;

import com.alibaba.fastjson.JSON;
import com.gxa.pojo.Result;
import com.gxa.pojo.goods.GoodsOneType;
import com.gxa.service.goods.GoodsOneTypeService;
import com.gxa.service.goods.impl.GoodsOneTypeServiceimpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(urlPatterns = "/GoodsOneSelectServlet")
public class GoodsOneSelectServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        GoodsOneTypeService goodsOneTypeService = new GoodsOneTypeServiceimpl();
        List<GoodsOneType> select = goodsOneTypeService.select();

        response.setContentType("text/json;charset=utf-8");
        Map<String, Object> map = new HashMap<>();
        if (select!=null){
            map.put("Result", Result.ok("查询成功",select));
        }else {
            map.put("Result",Result.error());
        }
        String s1 = JSON.toJSONString(map);
        response.getWriter().write(s1);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
